package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.SaveSysActivityDetail;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysActivityDetailMapper;
import com.ruoyi.system.domain.SysActivityDetail;
import com.ruoyi.system.service.ISysActivityDetailService;

/**
 * 活动详情Service业务层处理
 *
 * @author ruoyi
 * @date 2022-01-29
 */
@Service
public class SysActivityDetailServiceImpl implements ISysActivityDetailService {
    @Autowired
    private SysActivityDetailMapper sysActivityDetailMapper;

    /**
     * 查询活动详情
     *
     * @param activityId 活动详情主键
     * @return 活动详情
     */
    @Override
    public SysActivityDetail selectSysActivityDetailByActivityId(Long activityId) {
        return sysActivityDetailMapper.selectSysActivityDetailByActivityId(activityId);
    }

    /**
     * 查询活动详情列表
     *
     * @param sysActivityDetail 活动详情
     * @return 活动详情
     */
    @Override
    public List<SysActivityDetail> selectSysActivityDetailList(SysActivityDetail sysActivityDetail) {
        if (!SecurityUtils.isTeacher()){
            sysActivityDetail.setUserId(SecurityUtils.getUserId());
        }

        return sysActivityDetailMapper.selectSysActivityDetailList(sysActivityDetail);
    }

    /**
     * 新增活动详情
     *
     * @param sysActivityDetailSave 活动详情
     * @return 结果
     */
    @Override
    public int insertSysActivityDetail(SaveSysActivityDetail sysActivityDetailSave) {
        SysActivityDetail sysActivityDetail = new SysActivityDetail();
        BeanUtils.copyProperties(sysActivityDetailSave, sysActivityDetail);
        sysActivityDetail.setCreateTime(DateUtils.getNowDate());
        sysActivityDetail.setApplyUserId(SecurityUtils.getUserId());
        sysActivityDetail.setApplyUserName(SecurityUtils.getUsername());
        sysActivityDetail.setApprovalStatus("0");
        return sysActivityDetailMapper.insertSysActivityDetail(sysActivityDetail);
    }

    /**
     * 修改活动详情
     *
     * @param sysActivityDetail 活动详情
     * @return 结果
     */
    @Override
    public int updateSysActivityDetail(SysActivityDetail sysActivityDetail) {
        return sysActivityDetailMapper.updateSysActivityDetail(sysActivityDetail);
    }

    /**
     * 批量删除活动详情
     *
     * @param activityIds 需要删除的活动详情主键
     * @return 结果
     */
    @Override
    public int deleteSysActivityDetailByActivityIds(Long[] activityIds) {
        return sysActivityDetailMapper.deleteSysActivityDetailByActivityIds(activityIds);
    }

    /**
     * 删除活动详情信息
     *
     * @param activityId 活动详情主键
     * @return 结果
     */
    @Override
    public int deleteSysActivityDetailByActivityId(Long activityId) {
        return sysActivityDetailMapper.deleteSysActivityDetailByActivityId(activityId);
    }
}
